package com.example.javatwo.service.xs.lyh;


import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.javatwo.mapper.xs.lyh.ISalesOrderDao;
import com.example.javatwo.pojo.xs.lyh.hissalesVo;
import com.example.javatwo.pojo.xs.lyh.historycheck;
import com.example.javatwo.pojo.xs.lyh.pageBean;
import com.example.javatwo.pojo.xs.lyh.salesorders;

@Service
public class SalesOrderBizImpl {
	
	@Autowired
	public ISalesOrderDao sdao;
	
	
	public pageBean querySalelyh(Map<String, Object> map){
		Integer page = Integer.valueOf(String.valueOf(map.get("page")));
		List<salesorders> sales = sdao.querySalelyh(page);
		Integer count = sdao.querySalesCount();
		pageBean pb = new pageBean(count, 1, page, sales);
		return pb;
	}
	
	public void insertSaleslyh(salesorders sales){
		if(this.sdao.querySalesCount()!=0){
			this.sdao.deleteSaleslyh(sales.getBillNo());
		}
		this.sdao.insertSaleslyh(sales);
	}
	
	public void updateSaleslyh(salesorders sales){
		this.sdao.updateSaleslyh(sales);
	}
	
	/**
	 * 审核与反审核
	 * @param sales
	 */
	public void updateShenHelyh(String isShenHe,String billNo){
		this.sdao.updateShenHelyh(isShenHe, billNo);
	}
	
	
	/**
	 * 销售订单：在我点击保存的时候对(历史查询记录)=》进行新增
	 * 但是如果客户第一次购买就不显示第二次显示
	 * @param his
	 */
	public void insertHistoryChecklyh(historycheck his){
		if(this.sdao.queryHislyh()!=0){
			this.sdao.deleteHislyh(his.getCustomerID());
		}
		this.sdao.insertHistoryChecklyh(his);
	}
	
	public List<hissalesVo> queryhissalesVolyh(String customerID){
		if(this.sdao.queryHisCountlyh(customerID)>1){
			return this.sdao.queryhissalesVolyh(customerID);
		}
		return null;
	}
}
